package examination;
import java.sql.ResultSet;
import java.sql.SQLException;


public class AccountBean {
	private String username;
	private int type;
	private String staffNo;
	private DatabaseBean account = new DatabaseBean();
	
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getStaffNo() {
		return staffNo;
	}
	public void setStaffNo(String staffNo) {
		this.staffNo = staffNo;
	}
	
	public boolean login(String _user_id,String _passwd)
	{
		try{
			String sql = "select * from users";
			ResultSet rs=account.executeQuery(sql);
			rs.beforeFirst();
			while(rs.next()) {
				if(rs.getString("user_id").equals(_user_id)&&rs.getString("passwd").equals(_passwd)) {
					this.setUsername(rs.getString("user_id"));
					this.setType(rs.getInt("usertype"));
					this.setStaffNo(rs.getString("teacher_id"));
					return true;//登录成功则将信息写入本类属性，以便取用
				}
			}
		}
		catch(SQLException e)
		{
			return false;
		}
		return false;
	}
	
}
